#encoding:utf8 
import os , sys , shutil
try:
	from py_ex import *
except:
	import logging

CMD_STR = {
	"win32":"ffmpeg -r 44100 -y -i %s %s.mp3",
	"ios":"afconvert -d aac -f 'caff' -c 1 %s %s.caf",
	"android":"ffmpeg -y -i %s -acodec libvorbis %s.ogg"
}

def formatAudio(path , platname):
	logging.info("Formating audio file from [%s] to platname [%s] needed"%(path , platname))
	platdir = os.path.join(path , platname)
	if os.path.isdir(platdir):
		shutil.rmtree(platdir)
	os.mkdir(platdir)
	for filename in os.listdir(path):
		fileobj = os.path.join(path , filename)
		if os.path.splitext(filename)[1] == '.wav' or os.path.splitext(filename)[1] == '.mp3':
			logging.error("@!No format tool ffmpeg and afconvert")

			#todo in win32
			if platname == "win32":
				sys.exit()
			os.system(CMD_STR[platname] % (fileobj , os.path.join(platdir , os.path.splitext(filename)[0])))
	logging.info("Formating finish!")